package com.baofu.paycore.common.enums;

import com.baofu.paycore.common.exception.PayCoreBaseException;
import com.baofu.paycore.service.facade.enums.PayCoreErrorCode;
import com.system.commons.exception.BizServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * 卡类型
 *
 * User: LZQ Date: 2016/04/21  Version: 1.0
 */
@Slf4j
@Getter
@AllArgsConstructor
public enum CardTypeEnum {

    DEBATE_CARD("D", "借记卡"),

    CREDIT_CARD("C", "贷记卡"),

    BANK_CARD("BANK_CARD", "银行卡"),

    UN("UN", "不限"),
    ;


    /** 枚举编码 */
    private String code;

    /** 描述说明 */
    private String description;

    /**
     * 通过枚举编码获得枚举
     *
     * @param code 枚举编码
     * @return     返回编码对应的枚举类型
     */
    public static CardTypeEnum getByCode(String code) {
        for (CardTypeEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        log.error("不支持的卡类型:{}",code);
        throw new BizServiceException(PayCoreErrorCode.VALUE_NOT_SUPPORT, "不支持的卡类型！"+code);
    }

}
